package com.htfyun.fragment.library;

import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.htfyun.ScanMyPictureDirManager;
import com.htfyun.fragment.base.BaseWithPageNumberAdapter;
import com.htfyun.fragment.base.BaseWithPageNumberFragment;
import com.htfyun.view.GridSpacingItemDecoration;
import com.squareup.picasso.Picasso;

import org.geometerplus.zlibrary.ui.android.R;

import java.io.File;
import java.util.List;

/**
 * Created by sst on 2017/12/26.
 */

public class LibraryImageFragment extends BaseWithPageNumberFragment<File> {

    public static final String PICASSO_TAG = "LibraryImageFragment";

    private static final int SPAN_COUNT = 4;

    public static LibraryImageFragment newInstance() {

        Bundle args = new Bundle();

        LibraryImageFragment fragment = new LibraryImageFragment();
        fragment.setArguments(args);
        return fragment;
    }
    
    @Override
    public void onDestroy() {
        super.onDestroy();
        Picasso.with(_mActivity).cancelTag(PICASSO_TAG);

    }

    @Override
    public RecyclerView.LayoutManager getLayoutManager() {
        return new GridLayoutManager(_mActivity, SPAN_COUNT);
    }

    @Override
    public RecyclerView.ItemDecoration getDecor() {
        int space = getContext().getResources().getDimensionPixelSize(R.dimen.library_img_cover_space);
        return (new GridSpacingItemDecoration(SPAN_COUNT, space, true));
    }

    @Override
    public BaseWithPageNumberAdapter getAdapter() {
        return new LibraryImageRecyclerViewAdapter(_mActivity);
    }

    @Override
    public int getItemCountPerPage() {
        return getContext().getResources().getInteger(R.integer.library_img_count_per_page);
    }

    @Override
    public List<File> getTotalItemList() {
        return ScanMyPictureDirManager.INSTANCE.getFiles();
    }

    @Override
    public String getStringForTextEmpty() {
        return getString(R.string.push_pictures_into_my_picture);

    }
}
